﻿using System.Collections.Generic;
using Natural.Attributes;
using Natural.Helpers;
using Natural.Managers;
using Natural.Model;

namespace Natural.Providers
{
    [Impl(Type = ImplType.Provider, Name = "Invoker", Strategy = "Default", Version = 0, Priority = 0)]
    public class DefaultInvoker : IInvoker
    {
        public void Invoke(InvokeContext context)
        {
            InvokeRequest request = context.Request;
            InvokeResponse response = context.Response;

            response.Results = new List<string>(request.Commands.Length);
            foreach (Command command in request.Commands)
            {
                ActionInfo actionInfo = Solver.ActionInfo(command.Entity, command.Action);
                object[] parameters = Solver.Parameters(actionInfo, command.Parameters);
                object result = Executor.Execute(context,actionInfo, parameters);
                response.Results.Add(result == null ? null : Serializer.Serialize(result));
            }
        }

        public void Dispose()
        {
            
        }
    }
}
